import { defineConfig, loadEnv, ConfigEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import * as path from 'path';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
// https://vitejs.dev/config/
export default defineConfig((mode: ConfigEnv) => {
    const env = loadEnv(mode.mode, process.cwd());
    return {
        base: env.VITE_BASE, //测试环境开启，线上环境关闭
        resolve: {
            //设置别名
            alias: {
                '@': path.resolve(__dirname, 'src'),
            },
            extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
        },
        css: {
            preprocessorOptions: {
                scss: {
                    additionalData: `@use "@/styles/index.scss" as *;`,
                },
            },
        },
        plugins: [
            vue(),
            AutoImport({
                resolvers: [ElementPlusResolver()],
            }),
            Components({
                resolvers: [ElementPlusResolver()],
            }),
            createSvgIconsPlugin({
                // 指定图标文件夹，绝对路径（NODE代码）
                iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')],
            }),
        ],
        server: {
            port: 8080, //启动端口
            hmr: {
                host: '127.0.0.1',
                port: 8080,
            },
            // 设置 https 代理
            // proxy: {
            //     '/api': {
            //         target: 'https://oss-arena.5eplay.com/',
            //         changeOrigin: true,
            //         rewrite: (path: string) => path.replace(/^\/api/, ''),
            //     },
            // },
        },
    };
});
